home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5083 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: passing struct to constructor  -  temp.txt [1/1]
  5. Date: Fri, 02 Feb 1996 14:46:02 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3112078A.1626@cmt.lpr.mail.carel.fi>
  8. References: <4eqgq3$5g1@geraldo.cc.utexas.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. W. Harris wrote:
  16. > The compiler error I'm getting is "VIN is not a member of struct1".  The
  17. > code has been severely minimized, however this should have the bare
  18. > essentials required to solve the problem.
  19. > class CarData
  20. >     {
  21. >     private :
  22. >     char VIN[7];
  23. >     public :
  24. >     CarData(struct astruct1 CarInf);
  25. >     };
  26. >     //********************************************************
  27. >      CarData::CarData(struct astruct1 CarInf)
  28. >       {
  29. >       strcpy(VIN,CarInf.VIN);
  30. >       }
  31. >       struct astruct1
  32. >         {
  33. >         char VIN[7];
  34. >         }CarInfo;
  35.  
  36. You'd want to define the struct:
  37.  
  38.     struct astrcut1 {
  39.         char    VIN[7];
  40.     };
  41.  
  42. before the definition of CarData. Here you'd just declare the instance:
  43.  
  44.     astruct1    CarInfo;
  45.  
  46. Also, bear in mind that in C++, struct behaves exactly as a class. The only difference is 
  47. that in a class, members are private by default, and in a struct, they default to public. 
  48.  
  49. >     void main()
  50. >      {
  51. >      CarData CarConst1(struct astruct1 CarInfo);
  52. >      }
  53.  
  54. Later,
  55.  AriL
  56. -- 
  57. All my opinions are mine and mine alone.
  58.